<templateSet group="php_snippets">
  <template name="pdo_connect" value="//---------------------------------------------------------------//&#10;$host = 'localhost';&#10;$db   = '$NAMEDB$';&#10;$user = '$NAMEUSER$';&#10;$pass = '$PASSKEY$';&#10;$charset = 'utf8mb4';&#10;&#10;$dsn = &quot;mysql:host=$host;dbname=$db;charset=$charset&quot;;&#10;$opt = array(&#10;    \PDO::ATTR_ERRMODE            =&gt; \PDO::ERRMODE_EXCEPTION,&#10;    \PDO::ATTR_DEFAULT_FETCH_MODE =&gt; \PDO::FETCH_ASSOC,&#10;    \PDO::ATTR_EMULATE_PREPARES   =&gt; false,&#10;    \PDO::MYSQL_ATTR_INIT_COMMAND =&gt; &quot;SET CHARACTER SET utf8&quot;&#10;);&#10;//$pdo = new \PDO($dsn, $user, $pass, $opt);&#10;try {&#10;    $pdo = new \PDO($dsn, $user, $pass, $opt);&#10;} catch (\PDOException $e) {&#10;    throw new \PDOException($e-&gt;getMessage(), (int)$e-&gt;getCode());&#10;}&#10;//---------------------------------------------------------------//" description="настройка подключения к БД" toReformat="false" toShortenFQNames="true">
    <variable name="NAMEDB" expression="" defaultValue="" alwaysStopAt="true" />
    <variable name="NAMEUSER" expression="" defaultValue="" alwaysStopAt="true" />
    <variable name="PASSKEY" expression="" defaultValue="" alwaysStopAt="true" />
    <context>
      <option name="PHP" value="true" />
    </context>
  </template>
  <template name="pdo_request" value="/********************************************************/&#10;$Param=$PARAM$;&#10;$sqlquery  = &quot;SELECT * FROM $TABLE$ WHERE $COLUMN$ = ? LIMIT 1;&quot;;&#10;$stmt =$pdo-&gt;prepare($sqlquery);&#10;$stmt-&gt;execute(array($PARAM$));&#10;$data = $stmt-&gt;fetchAll();&#10;foreach($data as $row)&#10;{   &#10;    print_r($row);&#10;}&#10;/********************************************************/" description="запрос к БД" toReformat="false" toShortenFQNames="true">
    <variable name="PARAM" expression="" defaultValue="" alwaysStopAt="true" />
    <variable name="TABLE" expression="" defaultValue="" alwaysStopAt="true" />
    <variable name="COLUMN" expression="" defaultValue="" alwaysStopAt="true" />
    <context>
      <option name="PHP" value="true" />
    </context>
  </template>
  <template name="pdo_transact" value="/** PDO TRANSACTION */&#10;/*fixme: check this, or add tpl */&#10; $querySelect=&quot;SELECT * FROM table1 where id_user= :id_user&quot;;&#10; $queryInsert=&quot;INSERT INTO table2 (val1, val2) VALUES(:num1,:color1), (:num2,:color2)&quot;;&#10; $pdo-&gt;beginTransaction();//начало&#10;    try {&#10;    $stmt = $pdo-&gt;prepare($querySelect);&#10;    $stmt-&gt;execute(array(&quot;:id_user&quot;=&gt;25));&#10;    $res1=$stmt-&gt;fetchAll();    &#10;    &#10;    $stmt = $pdo-&gt;prepare($queryInsert);&#10;    $stmt-&gt;execute(array(&quot;:num1&quot;=&gt;1,&quot;:color1&quot;=&gt;'red',&quot;:num2&quot;=&gt;2,&quot;:color2&quot;=&gt;'green'));&#10;    $rew2=$stmt-&gt;fetchAll();&#10;    } catch (Exception $e) {&#10;            $pdo-&gt;rollBack();//откат&#10;            header('Content-Type: application/json', true, 500);&#10;            echo json_encode([&quot;result:&quot; =&gt; &quot;db_error!&quot;, &quot;request&quot; =&gt; $e-&gt;getMessage()]);&#10;    }&#10;    &#10;    $pdo-&gt;commit();//фиксация&#10;/** End of pdo transacction */" description="шаблон транзакции (есть нюансы, см. офиц. документацию)" toReformat="false" toShortenFQNames="true">
    <context>
      <option name="PHP" value="true" />
    </context>
  </template>
  <template name="curl_debug" value="/***************************************************/&#10;$fp_err = fopen($_SERVER['DOCUMENT_ROOT'].'/verbose_file.txt', 'ab+');&#10;fwrite($fp_err, date('Y-m-d H:i:s').&quot;\n\n&quot;); //add timestamp to the verbose log&#9;             &#10;curl_setopt($ch, CURLOPT_VERBOSE, true);&#10;curl_setopt($ch, CURLOPT_FAILONERROR, true);&#10;curl_setopt($ch, CURLOPT_STDERR, $fp_err);&#10;/****************************************************/" description="использование отладки curl" toReformat="false" toShortenFQNames="true">
    <context>
      <option name="PHP" value="true" />
    </context>
  </template>
  <template name="setLog_0x" value="//*************************************************************************************//&#10;define('LOG_PATH_0x', __DIR__ . '/loggers_0x_2.log');&#10;function setLog_0x($str, $file = LOG_PATH_0x)&#10;{&#10;    if ($file === &quot;default&quot;) {&#10;        $file = LOG_PATH;&#10;    }&#10;    $tmp_file = fopen($file, 'a');&#10;    $date = date('Y-m-d H:i:s');&#10;    $str_res = $date . &quot; =&gt;  &quot; . $str;&#10;    fwrite($tmp_file, $str_res . &quot;\r\n&quot;);&#10;    fclose($tmp_file);&#10;    return 0;&#10;}&#10;//*************************************************************************************//" description="logger simple" toReformat="false" toShortenFQNames="true">
    <context>
      <option name="PHP" value="true" />
    </context>
  </template>
  <template name="get_json" value="// Takes raw data from the request&#10;$json = file_get_contents('php://input');&#10;&#10;// Converts it into a PHP object&#10;$data = json_decode($json);" description="template for get json from raw_data (data was been sended with header 'Application/json')" toReformat="false" toShortenFQNames="true" />
  <template name="eco" value="echo &quot;$END$&quot;;" description="'echo' statement" toReformat="true" toShortenFQNames="true">
    <context>
      <option name="PHP Statement" value="true" />
    </context>
  </template>
  <template name="fore" value="foreach ($ITERABLE$ as $VAR_VALUE$) {&#10;    $END$&#10;}" description="foreach(iterable_expr as $value) {...}" toReformat="true" toShortenFQNames="true">
    <variable name="ITERABLE" expression="" defaultValue="" alwaysStopAt="true" />
    <variable name="VAR_VALUE" expression="phpSuggestVariableName()" defaultValue="&quot;$item&quot;" alwaysStopAt="true" />
    <context>
      <option name="PHP Statement" value="true" />
    </context>
  </template>
  <template name="forek" value="foreach ($ITERABLE$ as $VAR_KEY$ =&gt; $VAR_VALUE$) {&#10;    $END$&#10;}" description="foreach(iterable_expr as $key =&gt; $value) {...}" toReformat="true" toShortenFQNames="true">
    <variable name="ITERABLE" expression="" defaultValue="" alwaysStopAt="true" />
    <variable name="VAR_KEY" expression="phpSuggestVariableName()" defaultValue="&quot;$index&quot;" alwaysStopAt="true" />
    <variable name="VAR_VALUE" expression="phpSuggestVariableName()" defaultValue="&quot;$item&quot;" alwaysStopAt="true" />
    <context>
      <option name="PHP Statement" value="true" />
    </context>
  </template>
  <template name="inc" value="include &quot;$END$&quot;;" description="'include' statement" toReformat="true" toShortenFQNames="true">
    <context>
      <option name="PHP Expression" value="true" />
      <option name="PHP Statement" value="true" />
    </context>
  </template>
  <template name="inco" value="include_once &quot;$END$&quot;;" description="'include_once' statement" toReformat="true" toShortenFQNames="true">
    <context>
      <option name="PHP Expression" value="true" />
      <option name="PHP Statement" value="true" />
    </context>
  </template>
  <template name="prif" value="private function $NAME$($PARAMETERS$){&#10;    $END$&#10;}" description="private function" toReformat="true" toShortenFQNames="true">
    <variable name="NAME" expression="" defaultValue="" alwaysStopAt="true" />
    <variable name="PARAMETERS" expression="phpVar" defaultValue="" alwaysStopAt="true" />
    <context>
      <option name="PHP Class Member" value="true" />
    </context>
  </template>
  <template name="prisf" value="private static function $NAME$($PARAMETERS$){&#10;    $END$&#10;}" description="private static function" toReformat="true" toShortenFQNames="true">
    <variable name="NAME" expression="" defaultValue="" alwaysStopAt="true" />
    <variable name="PARAMETERS" expression="phpVar" defaultValue="" alwaysStopAt="true" />
    <context>
      <option name="PHP Class Member" value="true" />
    </context>
  </template>
  <template name="prof" value="protected function $NAME$($PARAMETERS$){&#10;    $END$&#10;}" description="protected function" toReformat="true" toShortenFQNames="true">
    <variable name="NAME" expression="" defaultValue="" alwaysStopAt="true" />
    <variable name="PARAMETERS" expression="phpVar" defaultValue="" alwaysStopAt="true" />
    <context>
      <option name="PHP Class Member" value="true" />
    </context>
  </template>
  <template name="prosf" value="protected static function $NAME$($PARAMETERS$){&#10;    $END$&#10;}" description="protected static function" toReformat="true" toShortenFQNames="true">
    <variable name="NAME" expression="" defaultValue="" alwaysStopAt="true" />
    <variable name="PARAMETERS" expression="phpVar" defaultValue="" alwaysStopAt="true" />
    <context>
      <option name="PHP Class Member" value="true" />
    </context>
  </template>
  <template name="pubf" value="public function $NAME$($PARAMETERS$){&#10;    $END$&#10;}" description="public function" toReformat="true" toShortenFQNames="true">
    <variable name="NAME" expression="" defaultValue="" alwaysStopAt="true" />
    <variable name="PARAMETERS" expression="phpVar" defaultValue="" alwaysStopAt="true" />
    <context>
      <option name="PHP Class Member" value="true" />
    </context>
  </template>
  <template name="pubsf" value="public static function $NAME$($PARAMETERS$){&#10;    $END$&#10;}" description="public static function" toReformat="true" toShortenFQNames="true">
    <variable name="NAME" expression="" defaultValue="" alwaysStopAt="true" />
    <variable name="PARAMETERS" expression="phpVar" defaultValue="" alwaysStopAt="true" />
    <context>
      <option name="PHP Class Member" value="true" />
    </context>
  </template>
  <template name="rqr" value="require &quot;$END$&quot;;" description="'require' statement" toReformat="true" toShortenFQNames="true">
    <context>
      <option name="PHP Expression" value="true" />
      <option name="PHP Statement" value="true" />
    </context>
  </template>
  <template name="rqro" value="require_once &quot;$END$&quot;;" description="'require_once' statement" toReformat="true" toShortenFQNames="true">
    <context>
      <option name="PHP Expression" value="true" />
      <option name="PHP Statement" value="true" />
    </context>
  </template>
  <template name="thr" value="throw new $END$" description="throw new" toReformat="true" toShortenFQNames="true">
    <context>
      <option name="PHP Statement" value="true" />
    </context>
  </template>
  <template name="recursive_iterator" value="//-------------------------------------------------------------------------------&#10;            $raw_array = [[1],[&quot;2&quot;=&gt;[3,4,5,6,7],&quot;8&quot;=&gt;[9,10,11]],[&quot;a&quot;,&quot;b&quot;,&quot;c&quot;],[[[d]]]];&#10;            $flatten_array = [];&#10;            $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($raw_array));&#10;            foreach($iterator as $value) {&#10;                array_push($flatten_array, $value);&#10;            }&#10;            print_r($flatten_array);&#10;//-------------------------------------------------------------------------------" description="SPL рекурсивный итератор" toReformat="false" toShortenFQNames="true">
    <context>
      <option name="PHP" value="true" />
    </context>
  </template>
</templateSet>